package com.hyjx.framework.component.operatelog.operatelogdetail;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 操作日志详细控制器
 */
@Controller
@RequestMapping("/operatelogdetail")
public class OperatelogDetailController {
    @Resource
    private OperatelogDetailService service;

    /**
     * 进入到信息查询页面
     *
     * @return
     */
    @RequestMapping(value = "/gotoList", method = RequestMethod.GET)
    public String gotoList(HttpServletRequest request) {
        return "framework/component/operatelog/list";
    }

    /**
     * 执行客户查询操作
     *
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "/queryList", method = RequestMethod.POST)
    @ResponseBody
    public String queryList(OperatelogDetailModel model, HttpServletRequest request) {
        if (model.getOlid() != null) {
            return service.queryList(model);
        } else
            return "[]";
    }

    /**
     * 跳转到增加页面
     *
     * @return
     */
    @RequestMapping(value = "/gotoAdd", method = {RequestMethod.GET, RequestMethod.POST})
    public String gotoAdd(HttpServletRequest request) {
        return "/operatelogdetail/add";
    }

    /**
     * 增加信息
     *
     * @param OperatelogDetailModel
     * @return
     */
    @RequestMapping(value = "/doAdd", method = RequestMethod.POST)
    @ResponseBody
    public String doAdd(OperatelogDetailModel model) {
        if (service.add(model)) {
            return "success";
        } else {
            return "failure";
        }
    }

    /**
     * 跳转到修改页面
     * request
     *
     * @return
     */
    @RequestMapping(value = "/gotoEdit", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView gotoEdit(HttpServletRequest request) {
        String id = request.getParameter("id");
        OperatelogDetailModel model = service.getInfoById(id);
        ModelAndView mav = new ModelAndView("/operatelogdetail/edit");
        mav.addObject("model", model);
        return mav;
    }

    /**
     * 修改信息
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/doEdit", method = RequestMethod.POST)
    @ResponseBody
    public String doEdit(OperatelogDetailModel model) {
        if (service.edit(model) > 0) {
            return "success";
        } else {
            return "failure";
        }
    }

    /**
     * 删除信息
     * request
     *
     * @return
     */
    @RequestMapping(value = "/gotoDelete", method = RequestMethod.GET)
    @ResponseBody
    public String gotoDelete(HttpServletRequest request) {
        String ids = request.getParameter("ids");
        if (service.delete(ids) > 0) {
            return "success";
        } else {
            return "failure";
        }
    }

    /**
     * 信息查看
     * request
     *
     * @return
     */
    @RequestMapping(value = "/gotoView", method = RequestMethod.GET)
    public ModelAndView gotoView(HttpServletRequest request) {
        String id = request.getParameter("id");
        OperatelogDetailModel model = service.getInfoById(id);
        ModelAndView mav = new ModelAndView("/operatelogdetail/view");
        mav.addObject("model", model);
        return mav;
    }
}